Skip to content

media: add bounded PCM playout and artifact-based NetEq comparisons - #8823

Merged
theomonnom merged 27 commits into
v2.0from
codex/media-stream-playout
Nov 28, 2026
Merged

theomonnom merged 27 commits into
v2.0from
codex/media-stream-playout

Conversation

@theomonnom

@theomonnom theomonnom commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Provider PCM arriving after an empty playback queue causes gaps and abrupt returns. Add bounded, synchronous playout in the media crate: adaptive reserve, pitch-preserving time scaling, mixed concealment, learned room tone and recovery merging.

Native mono 16/24/48 kHz PCM16, selected once in Config::sample_rate (default 24 kHz). Arbitrary chunks; render 1 sample through 20 ms. Playout::continuous(config) needs no boundaries and exposes finish(). Playout::segmented(config) exposes begin_segment() / end_segment() and retains normalized delivery timing. Distinct types share the same DSP and buffers.

NetEq-aligned processing: 30 ms time-scale window, whole-period crossfade, 0.9/0.5 normal/fast correlation, about 50 ms ordinary spacing and emergency acceleration above four times the high-delay threshold. The 3% quota/profile is removed. Current relative playout delay drives decisions directly, as in NetEq; no extra smoothing gate delays catch-up. Keep the provider-specific startup protection: configurable 80 ms cold hold, protected early reserve, burst/EOF release and learned segment startup. Default target remains 20–100 ms; queue capacity 2 s.

Listen

Same captured GPTLive speech (marin), gain and ordered source per row. Start/Slow: 3 s; others: 6 s. Common wall-clock crops preserve initial wait. Links show measured added startup delay (1 ms signal-onset analysis), excluding model, live network and device latency. Minimal 32×32 MP4 attachments; no media binaries or attachment/plot generation scripts are committed.

Case Untreated WebRTC Rust
Start (@ 0.1s)
late-start-untreated.mp4
late-start-neteq.mp4
late-start-rust.mp4
Slow (@ 0.1s)
slow-start-untreated.mp4
slow-start-neteq.mp4
slow-start-rust.mp4
Jitter (@ 2.2s)
slow-jitter-untreated.mp4
slow-jitter-neteq.mp4
slow-jitter-rust.mp4
Stalls (@ 2.2s)
repeated-stalls-untreated.mp4
repeated-stalls-neteq.mp4
repeated-stalls-rust.mp4
Outage (@ 2.2s)
stall-1s-untreated.mp4
stall-1s-neteq.mp4
stall-1s-rust.mp4
Catchup (@ 2.2s)
catch-up-untreated.mp4
catch-up-neteq.mp4
catch-up-rust.mp4

Start: second chunk 60 ms late. Slow: first 400 ms delivered at 1.8× the nominal interval, accumulating 320 ms lag. Jitter: 20 s of 1%-slow delivery plus 0–30 ms jitter. Stalls: four 80 ms pacing pauses with retained delay. Outage: 1 s pause. Catchup: 1.5 s of source at 3× speed. Synthetic, report-inspired stress cases; not customer trace replays.

Learning across answers

Answer 2 after one training answer. Identical source, arrivals, DSP and settings; only timing retention changes. Both use a 20 ms cold prior and an explicit 400 ms maximum, with the Slow schedule above. First-answer controls are byte-identical; duplicate listening links are omitted.

Mode Audio Startup Underruns
Reset
learn-reset.mp4
20 ms 4
Retain
learn-retained.mp4
340 ms 0

Cost: +320 ms startup, avoiding 290.4 ms of concealment in this replay. This is not the default 100 ms cap. With clean segment arrivals, the default startup hold relaxes 80 → 60 → 40 → 20 ms; recent bad history can keep it elevated longer.

Timing

Catch-up queued audio at 20 s: Rust 190 ms / NetEq 196 ms. Both queue counters include pending output. The plot shows 100 ms means with faint min/max ranges; the quoted 20 s values are raw samples. Queues need not be identical: startup protection, chunk-aware arrival estimates and independent DSP remain different. The native reference keeps its own unlimited target maximum; the script supports an explicit alternative cap.

Playout timing

Validation

238 Rust runtime tests + 2 API compile-fail tests pass, one existing ignored. External audit checks verified off-grid stalls, valid short controls/startup, and incomplete repeated-stall schedules. An additional 288 seeded stress cases pass across all rates, capacities, irregular render sizes, overflow atomicity, drain/reset and long clock epochs. Coverage includes native-rate pitch/energy/recovery, clean PCM preservation, startup learning, continuous silence/resumption, cadence/emergency catch-up, exact source accounting, atomic errors, EOF and zero allocations on the audio path. Purity-policy Clippy, formatting, strict mypy, Ruff and architecture checks pass.

All seven posted Devin findings were reproduced and addressed. Quiet splice preference is shared across search paths; local seam checks are shared by normal and history-based time scaling, accept identical clipped plateaus and reject unequal flat windows. Startup replay schedules require an actual resumed nominal interval. External checks cover 36 startup recovery boundaries across rates and chunk sizes. Immutable schedules own actual chunk-boundary fault events, validate complete source/event coverage before compilation, and supply both injection timing and report labels. Concurrent comparison builds have distinct runner names. The comparison script contains no embedded tests. Fresh replays across all three rates reproduce all 360 existing audio/trace files byte-for-byte after the latest review fixes.

All 12 presets × 3 rates rendered against pinned actual NetEq. Only the reference converts to/from 48 kHz for L16, retaining each enclosing chunk's arrival time. The standalone neteq_compare.py records settings, seed, hashes, queues, operation traces and pre-EOF counters; fixed inputs/toolchain make retries deterministic.

The rate-only change (2bb44b7ca5) preserved all previous 24 kHz PCM and traces byte-for-byte. The subsequent explicit cadence/splice tuning intentionally changes playback; the current deterministic PCM golden pins that latest behavior. API and comparison usage.

This is not enabled in live sessions. Provider/runtime wiring and broader listening review remain; matching features and timing does not establish perceptual parity.

@theomonnom
theomonnom force-pushed the codex/media-stream-playout branch from d155da2 to 7e1b936 Compare November 28, 2026 03:16
@theomonnom theomonnom changed the title media: add bounded PCM playout and NetEq comparison fixtures media: add bounded PCM playout and artifact-based NetEq comparisons Nov 28, 2026
@theomonnom
theomonnom marked this pull request as ready for review November 28, 2026 08:24
@theomonnom
theomonnom requested a review from a team as a code owner November 28, 2026 08:24
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@theomonnom
theomonnom merged commit f3eaa22 into v2.0 Nov 28, 2026
9 of 15 checks passed
@theomonnom
theomonnom deleted the codex/media-stream-playout branch November 28, 2026 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant